<?php
//==============================================
// 代码所有       PHPText.Net
// 代码作者       黄创钦,tine2cx@163.com
// 联系方式       QQ 233944397
// 本代码开源使用，可以随意修改传播，但请保留本版权
// 声明,谢谢合作！
//==============================================

	error_reporting(E_ALL&~E_NOTICE);

	if(PHP_VERSION < '4.1.0')
	{
		$_GET    = &$HTTP_GET_VARS;
		$_POST   = &$HTTP_POST_VARS;
		$_COOKIE = &$HTTP_COOKIE_VARS;
		$_SERVER = &$HTTP_SERVER_VARS;
		$_ENV    = &$HTTP_ENV_VARS;
		$_FILES  = &$HTTP_POST_FILES;
	}

	//更正PHP5时间
	if(function_exists("date_default_timezone_set"))
	{
		//PHP5的函数，强制设置时区为中国
		date_default_timezone_set("PRC");
	}

	define("_SimNumber_","零,一,二,三,四,五,六,七,八,九");
	define("_SimDigit_","十,百,千,万,亿");
	define("_CapNumber_","零,壹,贰,叁,肆,伍,陆,柒,捌,玖");
	define("_CapDigit_","拾,佰,仟,万,亿");

	define("_BoardFields_","分类名称,分类描述,论坛个数,SID管理员,创建时间");
	define("_ForumFields_","论坛名称,论坛描述,论坛模式,SID版主,主题数,帖子数,今日帖子,创建时间");
	define("_TopicFields_","主题,内容,模式,SID发表人,发表IP,SID修改人,修改IP,修改时间,回复数,浏览数,创建时间");
	define("_ReplyFields_","内容,模式,SID答复人,答复IP,SID修改人,修改IP,修改时间,创建时间");
	define("_MBoxFields_","标题,内容,状态,SID发送人,发送IP,创建时间");

	define("_TopicListFields_","板块ID,论坛ID,主题ID,主题标题,SID发表人,回复数,浏览数,模式,创建时间");
	define("_ReplyListFields_","板块ID,论坛ID,主题ID,帖子ID,SID发表人,模式,创建时间");
	define("_TRListFields_","板块ID,论坛ID,主题ID,帖子ID,主题标题,SID发表人,回复数,浏览数,模式,创建时间");

	define("_NowTimes_",mktime(0,0,0,date('m'),date('d'),date('Y')));
	define("_LastTimes_",mktime(0,0,0,date('m'),date('d'),date('Y'))-86400);

	//系统字串冲突排除函数
	function SysStr($Str)
	{
		//v系列684代字串-685字串
		$Str=str_replace("","",$Str);
		return $Str;
	}

	//提示信息
	function JSAlert($mes,$back=0)
	{
		echo "<script type='text/javascript' src='JSCookie.js'></script>";
		echo "<script type='text/javascript'>";
		echo "alert('".$mes."');";

		if($back)
		{
			echo "window.parent.history.go(-1);";
		}

		echo "</script>";

		if($back)
		{
			die();
		}
	}

	//JS 设置COOKIE
	function JSAddCookie($Name,$Val,$Hour)
	{
		echo "<script type='text/javascript' src='JSCookie.js'></script>";
		$Cookie = "<script type='text/javascript'>";
		if(is_array($Name))
		{
			for($id = 0;$id < sizeof($name); $id++)
			{
				$Cookie .= "addCookie('".$Name."','".$Val."','".$Hour."');";
			}
		}
		else
		{
			$Cookie .= "addCookie('".$Name."','".$Val."','".$Hour."');";
		}
		$Cookie .= "</script>";

		echo $Cookie;
	}

	//JS 删除COOKIE
	function JSDeleteCookie($Name)
	{
		$Cookie = "<script type='text/javascript'>";
		if(is_array($Name)){
			for($id = 0;$id < sizeof($name); $id++)
			{
				$Cookie .= "deleteCookie('".$Name."');";
			}
		}
		else
		{
			$Cookie .= "deleteCookie('".$Name."');";
		}
		$Cookie .= "</script>";

		echo $Cookie;
	}

	//加密IP地址
	function ENIP($ip,$style="1100")
	{
		if(!empty($ip) and strstr($ip,"."))
		{
			$ip=explode(".",$ip);
			$style=(string)$style;
			for($i=0;$i<4;$i++){
				if(!$style[$i]){
					$ip[$i]="*";
				}
			}
			$ip=implode(".",$ip);
			return $ip;
		}
		else
		{
			return false;
		}
	}

	//去除所有换行符
	function RNRTString($Str)
	{
		$Str = str_replace("\r",' ',$Str);
		$Str = str_replace("\n",' ',$Str);
		$Str = str_replace("\t",' ',$Str);
		return $Str;
	}

	//去除模板标记
	function RMTString($Str)
	{
		$Str = str_replace('<!--#Mod#-->','',$Str);
		$Str = str_replace('<!--#Mod#','',$Str);
		$Str = str_replace('#Mod#-->','',$Str);
		$Str = str_replace('<!--#Mod','',$Str);
		$Str = str_replace('#-->','',$Str);

		return $Str;
	}

	//网站头部
	function _Header($_PageName=NULL)
	{
		global $_SiteName_,$_SiteDesc_,$_SiteKeys_,$_TitleSEO_,$_ContsSEO_,$Menu,$Nav,$NavMain,$ServerDate,$DateWeek;
		global $OnlineDisplay,$OLIcon,$OnlineUser,$OnlineGuest,$OnlineMax,$Online,$LinkDisplay,$TLinks,$PLinks;

		$_ContsSEO_ = RNRTString($_ContsSEO_);

		ob_start();

		if(!empty($_TMADDSEO_))
		{
			$_PageName = $_TMADDSEO_ .' - '. $_PageName;
		}

		require GetMod('Header');
	}

	//网站底部
	function _Footer()
	{
		global $_SiteName_,$_SiteDesc_,$_SiteKeys_,$_TitleSEO_,$_ContsSEO_,$Menu,$Nav,$NavMain,$ServerDate,$DateWeek;
		global $OnlineDisplay,$OLIcon,$OnlineUser,$OnlineGuest,$OnlineMax,$Online,$LinkDisplay,$TLinks,$PLinks;
		require GetMod('Footer');
		$_WebContent = ob_get_contents();
		$_WebContent = RMTString($_WebContent);
		ob_end_clean();
		echo $_WebContent;
	}

	//获取模板
	function GetMod($_ModFileName)
	{
		return _SkinPath_.'/_'.$_ModFileName.'.htm';
	}

	//显示提示消息
	function ShowMegBox($_Meg,$_Url=NULL,$_Mode)
	{
		global $_SiteName_,$_SiteDesc_,$_SiteKeys_,$_TitleSEO_,$_ContsSEO_,$Menu,$Nav,$NavMain,$ServerDate,$DateWeek,$OnlineDisplay,$OLIcon,$OnlineUser,$OnlineGuest,$OnlineMax,$Online,$LinkDisplay,$TLinks,$PLinks;

		define("_ShowMegBox_",true);

		//获取传入参数
		$_Meg  = $_Meg;
		$_Url  = $_Url;
		$_Mode = $_Mode;

		//检测是否自定义模板
		if(_CustomErrorSkin_)
		{
			ob_start();
		}
		else
		{
			_Header('信息提示');
		}

		require GetMod('Meg',$_ModClass);

		//检测是否自定义模板
		if(_CustomErrorSkin_)
		{
			$_WebContent = ob_get_contents();
			$_WebContent = RMTString($_WebContent);
			ob_end_clean();
			echo $_WebContent;
		}
		else
		{
			_Footer();
		}

		die();
	}

	//跳转
	function JSUrl($url)
	{
		echo "<script type='text/javascript'>";
		echo "location='".$url."';";
		echo "</script>";
		die();
	}

	function GetSID()
	{
		return md5(uniqid(rand().date("U").((double)microtime()*1000000)));
	}

	//检测邮件地址
	function is_EMail($str)
	{
		return preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $str);
	}

	//检测网页地址
	function is_Url($str)
	{
		return preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])*$/", $str);
	}

	//检测QQ
	function is_QQ($str)
	{
		return preg_match("/^[1-9]\d{4,8}$/", $str);
	}

	//检测邮编
	function is_Zip($str)
	{
		return preg_match("/^[1-9]\d{5}$/", $str);
	}

	//检测身份证
	function is_IDCard($str)
	{
		return preg_match("/^\d{15}(\d{2}[A-Za-z0-9])?$/", $str);
	}

	//检测中文
	function is_Chinese($str)
	{
		return ereg("^[".chr(0xa1)."-".chr(0xff)."]+$",$str);
	}

	//检测英文
	function is_English($str)
	{
		return preg_match("/^[A-Za-z]+$/", $str);
	}

	//检测手机
	function is_Mobile($str)
	{
		return preg_match("/^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/", $str);
	}

	//检测固话
	function is_Phone($str)
	{
		return preg_match("/^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/", $str);
	}

	//检测密码
	function is_Safe($str)
	{
		return (preg_match("/^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/", $str) != 0);
	}

	//检测是否为论坛管理人员
	function CheckForumAdmin()
	{
		if(_UserLogin_)
		{
			if(_LoginJobs_==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	//检测是否为论坛管理是否多于一位
	function CheckForumAdminNum($AdminName=null)
	{
		$MembersInfo = TextDB_SearchData("Members","权限",1);
		if(sizeof($MembersInfo)>1)
		{
			return true;
		}
		if(!empty($AdminName))
		{
			if($MembersInfo[0]["昵称"]==$AdminName)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		return false;
	}

	//检测是否为超级版主
	function CheckForumRoot()
	{
		if(_UserLogin_){
			if(_LoginJobs_==2)
			{
				return true;
			}
			else
			{
				return false;
			}
		}else{
			return false;
		}
	}

	//检测是否为分类管理人员
	function CheckBoardRoot($BID)
	{
		if(empty($BID))
		{
			return false;
		}

		if(_UserLogin_)
		{
			$BoardInfo = TextDB_SearchData("Board","TEXTDB_HID",$BID);  //获取子板块信息

			if(!$BoardInfo)
			{
				return false;
			}

			$root      = explode("",$BoardInfo[0]["SID管理员"]);
			if(_LoginID_==$root[0])
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	//检测论坛是否枷锁
	function CheckForumMode($BID,$FID)
	{
		if(empty($BID) || empty($FID))
		{
			return false;
		}

		$ForumInfo = TextDB_SearchData("Forum_B".$BID,"TEXTDB_HID",$FID);  //获取子板块信息

		if(!$ForumInfo)
		{
			return false;
		}

		if($ForumInfo[0]["论坛模式"])
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	//检测是否为论坛版主
	function CheckRoot($BID,$FID)
	{
		if(empty($BID) || empty($FID))
		{
			return false;
		}

		if(_UserLogin_)
		{
			$ForumInfo = TextDB_SearchData("Forum_B".$BID,"TEXTDB_HID",$FID);  //获取子板块信息

			if(!$ForumInfo)
			{
				return false;
			}

			$root      = explode("",$ForumInfo[0]["SID版主"]);
			if(_LoginID_==$root[0])
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	//检测是否为主题发布者
	function CheckTopicRoot($BID,$FID,$TID)
	{
		if(empty($BID) || empty($FID) || empty($TID))
		{
			return false;
		}

		if(_UserLogin_)
		{
			$TopicInfo = TextDB_SearchData("Topic_B".$BID."_F".$FID,"TEXTDB_HID",$TID);

			if(!$TopicInfo)
			{
				return false;
			}

			$root      = explode("",$TopicInfo[0]["SID发表人"]);
			if(_LoginID_==$root[0])
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	//检测是否为主题答复人
	function CheckReplyRoot($BID,$FID,$TID,$RID)
	{
		if(empty($BID) || empty($FID) || empty($TID) || empty($RID))
		{
			return false;
		}

		if(_UserLogin_)
		{
			$ReplyInfo = TextDB_SearchData("Reply_B".$BID."_F".$FID."_T".$TID,"TEXTDB_HID",$RID);

			if(!$ReplyInfo)
			{
				return false;
			}

			$root      = explode("",$ReplyInfo[0]["SID答复人"]);
			if(_LoginID_==$root[0])
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	//更新主题、帖子列表
	function UpdateTRA($Action,$BoardID=NULL,$ForumID=NULL,$TopicID=NULL,$ReplyID=NULL)
	{
		if($Action!='重建' && (empty($BoardID) || empty($ForumID) || empty($TopicID)))
		{
			return false;
		}

		$ForumInfo = TextDB_SearchData("Forum_B".$BoardID,'TEXTDB_HID',$ForumID);
		$ForumMode = $ForumInfo[0]['论坛模式'];

		if($Action=='添加')
		{
			if(empty($ReplyID)) //没有回复ID
			{
				//添加主题
				$TopicInfo = TextDB_SearchData("Topic_B".$BoardID."_F".$ForumID,'TEXTDB_HID',$TopicID);
				if($TopicInfo)
				{
					//建立保存数据
					$TopicListInfo = array($BoardID,$ForumID,$TopicID,$TopicInfo[0]['主题'],$TopicInfo[0]['SID发表人'],$TopicInfo[0]['回复数'],$TopicInfo[0]['浏览数'],$ForumMode,$TopicInfo[0]['创建时间']);
					$ALLListInfo   = array($BoardID,$ForumID,$TopicID,'0',$TopicInfo[0]['主题'],$TopicInfo[0]['SID发表人'],$TopicInfo[0]['回复数'],$TopicInfo[0]['浏览数'],$ForumMode,$TopicInfo[0]['创建时间']);

					//主题列表添加
					$SaveInfo = array($BoardID,$ForumID,$TopicID);
					if(!TextDB_SearchData('ALL_TopicList','板块ID,论坛ID,主题ID',$SaveInfo))
					{
						TextDB_InsertData('ALL_TopicList','*',$TopicListInfo);
					}

					//分类主题列表添加
					if(!TextDB_SearchData("Board{$BoardID}_TopicList",'板块ID,论坛ID,主题ID',$SaveInfo))
					{
						TextDB_InsertData("Board{$BoardID}_TopicList",'*',$TopicListInfo);
					}

					//总列表添加
					$SaveInfo = array($BoardID,$ForumID,$TopicID,0);
					if(!TextDB_SearchData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData('ALL_TRList','*',$ALLListInfo);
					}

					//分类总列表添加
					if(!TextDB_SearchData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData("Board{$BoardID}_TRList",'*',$ALLListInfo);
					}

					//论坛总列表添加
					if(!TextDB_SearchData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData("Forum{$ForumID}_TRList",'*',$ALLListInfo);
					}

					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				//添加回复
				$ReplyInfo = TextDB_SearchData("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID,'TEXTDB_HID',$ReplyID);
				if($ReplyInfo)
				{
					//建立保存数据
					$ReplyListInfo = array($BoardID,$ForumID,$TopicID,$ReplyID,$ReplyInfo[0]['SID发表人'],$ForumMode,$ReplyInfo[0]['创建时间']);
					$ALLListInfo   = array($BoardID,$ForumID,$TopicID,$ReplyID,'',$ReplyInfo[0]['SID发表人'],0,0,$ForumMode,$ReplyInfo[0]['创建时间']);

					//总回复列表添加
					$SaveInfo = array($BoardID,$ForumID,$TopicID,$ReplyID);
					if(!TextDB_SearchData('ALL_ReplyList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData('ALL_ReplyList','*',$ReplyListInfo);
					}

					//分类回复列表添加
					if(!TextDB_SearchData("Board{$BoardID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData("Board{$BoardID}_ReplyList",'*',$ReplyListInfo);
					}

					//论坛回复列表添加
					if(!TextDB_SearchData("Forum{$ForumID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData("Forum{$ForumID}_ReplyList",'*',$ReplyListInfo);
					}

					//总列表添加
					$SaveInfo = array($BoardID,$ForumID,$TopicID,$ReplyID);
					if(!TextDB_SearchData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData('ALL_TRList','*',$ALLListInfo);
					}

					//分类总列表添加
					if(!TextDB_SearchData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData("Board{$BoardID}_TRList",'*',$ALLListInfo);
					}

					//论坛总列表添加
					if(!TextDB_SearchData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						TextDB_InsertData("Forum{$ForumID}_TRList",'*',$ALLListInfo);
					}

					return true;
				}
				else
				{
					return false;
				}
			}
		}
		elseif($Action=='更新')
		{
			if(empty($ReplyID)) //没有回复ID
			{
				//更新主题
				$TopicInfo = TextDB_SearchData("Topic_B".$BoardID."_F".$ForumID,'TEXTDB_HID',$TopicID);
				if($TopicInfo)
				{
					//建立保存数据
					$TopicListInfo = array($BoardID,$ForumID,$TopicID,$TopicInfo[0]['主题'],$TopicInfo[0]['SID发表人'],$TopicInfo[0]['回复数'],$TopicInfo[0]['浏览数'],$ForumMode,$TopicInfo[0]['创建时间']);
					$ALLListInfo   = array($BoardID,$ForumID,$TopicID,'0',$TopicInfo[0]['主题'],$TopicInfo[0]['SID发表人'],$TopicInfo[0]['回复数'],$TopicInfo[0]['浏览数'],$ForumMode,$TopicInfo[0]['创建时间']);
					$SaveInfo = array($BoardID,$ForumID,$TopicID);

					//主题列表更新
					$SaveInfo = array($BoardID,$ForumID,$TopicID);
					if(!TextDB_SearchData('ALL_TopicList','板块ID,论坛ID,主题ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID);
					}
					else
					{
						TextDB_ChangeData('ALL_TopicList','板块ID,论坛ID,主题ID',$SaveInfo,'*',$TopicListInfo);
					}

					//分类主题列表更新
					if(!TextDB_SearchData("Board{$BoardID}_TopicList",'板块ID,论坛ID,主题ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID);
					}
					else
					{
						TextDB_ChangeData("Board{$BoardID}_TopicList",'板块ID,论坛ID,主题ID',$SaveInfo,'*',$TopicListInfo);
					}

					//总列表更新
					$SaveInfo = array($BoardID,$ForumID,$TopicID,0);
					if(!TextDB_SearchData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID);
					}
					else
					{
						TextDB_ChangeData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ALLListInfo);
					}

					//分类总列表更新
					if(!TextDB_SearchData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID);
					}
					else
					{
						TextDB_ChangeData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ALLListInfo);
					}

					//论坛总列表更新
					if(!TextDB_SearchData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID);
					}
					else
					{
						TextDB_ChangeData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ALLListInfo);
					}

					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				//更新回复
				$ReplyInfo = TextDB_SearchData("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID,'TEXTDB_HID',$ReplyID);
				if($ReplyInfo)
				{
					//建立保存数据
					$ReplyListInfo = array($BoardID,$ForumID,$TopicID,$ReplyID,$ReplyInfo[0]['SID发表人'],$ForumMode,$ReplyInfo[0]['创建时间']);
					$ALLListInfo   = array($BoardID,$ForumID,$TopicID,$ReplyID,'',$ReplyInfo[0]['SID发表人'],0,0,$ForumMode,$ReplyInfo[0]['创建时间']);

					//回复列表更新
					$SaveInfo = array($BoardID,$ForumID,$TopicID,$ReplyID);
					if(!TextDB_SearchData('ALL_ReplyList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID,$ReplyID);
					}
					else
					{
						TextDB_ChangeData('ALL_ReplyList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ReplyListInfo);
					}

					//分类回复列表更新
					if(!TextDB_SearchData("Board{$BoardID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID,$ReplyID);
					}
					else
					{
						TextDB_ChangeData("Board{$BoardID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ReplyListInfo);
					}

					//论坛回复列表更新
					if(!TextDB_SearchData("Forum{$ForumID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID,$ReplyID);
					}
					else
					{
						TextDB_ChangeData("Forum{$ForumID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ReplyListInfo);
					}

					//总列表更新
					$SaveInfo = array($BoardID,$ForumID,$TopicID,$ReplyID);
					if(!TextDB_SearchData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID,$ReplyID);
					}
					else
					{
						TextDB_ChangeData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ALLListInfo);
					}

					//分类总列表更新
					if(!TextDB_SearchData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID,$ReplyID);
					}
					else
					{
						TextDB_ChangeData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ALLListInfo);
					}

					//论坛总列表更新
					if(!TextDB_SearchData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo))
					{
						UpdateTRA('添加',$BoardID,$ForumID,$TopicID,$ReplyID);
					}
					else
					{
						TextDB_ChangeData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo,'*',$ALLListInfo);
					}

					return true;
				}
				else
				{
					return false;
				}
			}
		}
		elseif($Action=='删除')
		{
			if(empty($ReplyID)) //没有回复ID
			{
				//主题列表删除
				$SaveInfo = array($BoardID,$ForumID,$TopicID);
				TextDB_DeleteData('ALL_TopicList','板块ID,论坛ID,主题ID',$SaveInfo);
				TextDB_DeleteData("Board{$BoardID}_TopicList",'板块ID,论坛ID,主题ID',$SaveInfo);

				//总列表删除
				$SaveInfo = array($BoardID,$ForumID,$TopicID,0);
				TextDB_DeleteData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);
				TextDB_DeleteData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);
				TextDB_DeleteData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);

				return true;
			}
			else
			{
				//回复列表删除
				$SaveInfo = array($BoardID,$ForumID,$TopicID,$ReplyID);
				TextDB_DeleteData('ALL_ReplyList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);
				TextDB_DeleteData("Board{$BoardID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);
				TextDB_DeleteData("Forum{$ForumID}_ReplyList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);

				//总列表删除
				$SaveInfo = array($BoardID,$ForumID,$TopicID,$ReplyID);
				TextDB_DeleteData('ALL_TRList','板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);
				TextDB_DeleteData("Board{$BoardID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);
				TextDB_DeleteData("Forum{$ForumID}_TRList",'板块ID,论坛ID,主题ID,帖子ID',$SaveInfo);

				return true;
			}
		}
		elseif($Action=='重建')
		{
			//设置无限制执行时间，避免大数据从建时间过长
			set_time_limit(0);

			$SNNum = 0;  //初始数据序号
			$AList = array();
			$E_Meg = ''; //初始错误提示信息

			//清除总表数据
			TextDB_CleanTable('ALL_TopicList');
			TextDB_CleanTable('ALL_ReplyList');
			TextDB_CleanTable('ALL_TRList');

			//获取板块信息
			$BoardList = TextDB_SearchData('Board');
			if($BoardList)
			{
				foreach($BoardList as $Board)
				{
					$BoardID   = $Board[0];

					//清除分类表数据
					TextDB_CleanTable("Board{$BoardID}_TopicList");
					TextDB_CleanTable("Board{$BoardID}_ReplyList");
					TextDB_CleanTable("Board{$BoardID}_TRList");

					$ForumList = TextDB_SearchData('Forum_B'.$BoardID);
					if($ForumList)
					{
						foreach($ForumList as $Forum)
						{
							$ForumID   = $Forum[0];

							//清除论坛表数据
							TextDB_CleanTable("Forum{$ForumID}_ReplyList");
							TextDB_CleanTable("Forum{$ForumID}_TRList");

							$TopicList = TextDB_SearchData("Topic_B".$BoardID."_F".$ForumID);
							if($TopicList)
							{
								foreach($TopicList as $Topic)
								{
									$TopicID   = $Topic[0];
									$ReplyList = TextDB_SearchData("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID);
									if($ReplyList)
									{
										foreach($ReplyList as $Reply)
										{
											$ReplyID = $Reply[0];
											//记录搜索信息
											$AList[$SNNum]['分类ID'] = $BoardID;
											$AList[$SNNum]['论坛ID'] = $ForumID;
											$AList[$SNNum]['主题ID'] = $TopicID;
											$AList[$SNNum]['回复ID'] = $ReplyID;
											$AList[$SNNum]['时间']   = $Reply['创建时间'];										}
									}
									else
									{
										$E_Meg .= "<br /><span color='blue'>主题【{$Topic['主题']}】没有回复，忽略回复重建。</span>";
									}

									//记录搜索信息
									$AList[$SNNum]['分类ID'] = $BoardID;
									$AList[$SNNum]['论坛ID'] = $ForumID;
									$AList[$SNNum]['主题ID'] = $TopicID;
									$AList[$SNNum]['回复ID'] = NULL;
									$AList[$SNNum]['时间']   = $Topic['创建时间'];
								}
							}
							else
							{
								$E_Meg .= "<br /><span color='blue'>论坛【{$Forum['论坛名称']}】没有主题，忽略主题重建。</span>";
							}
						}

						//排序
						$AList = TextDB_OrderData($AList,'时间');
						if($AList)
						{
							foreach($AList as $A)
							{
								UpdateTRA('添加',$A['分类ID'],$A['论坛ID'],$A['主题ID'],$A['回复ID']);
							}
						}
					}
					else
					{
						$E_Meg .= "<br /><span color='blue'>分类【{$Board['分类名称']}】没有建立论坛，忽略论坛重建。</span>";
					}
				}

				$E_Meg .= "<br /><br />";

				if(!empty($TAL))
				{
					//排列数据
					$TAL = TextDB_OrderData($TAL,'数据');
					if($TAL)
					{
						foreach($TAL as $T)
						{
							TextDB_InsertData('ALL_TopicList','*',$TopicListInfo);
						}
					}
				}
			}
			else
			{
				$E_Meg .= "<span color='blue'>没有找到分类信息，无法重建列表！</span>";
			}

			ShowMegBox("<div style='text-align:left'>列表重建完毕。<br /><br />".$E_Meg."</div>",$_SERVER["HTTP_REFERER"],'goto');
		}
		else
		{
			return false;
		}
	}

	//更新缓存
	function UpdateCache($CacheName,$CacheVal=null,$UpdateClass=null)
	{
		$CacheInfo = TextDB_SearchData("ForumCache","项目名",$CacheName);

		//更新昨日缓存
		if($CacheName=='昨日')
		{
			//获取缓存中今日信息
			$OldCache = TextDB_SearchData("ForumCache","项目名","今日");

			//如果缓存日期是昨天,则更新缓存
			if($OldCache[0]['创建时间']<_NowTimes_)
			{
				$CacheVal    = array($OldCache[0]['数值'],time());
				$NewCacheVal = array(0,time());

				TextDB_ChangeData('ForumCache','项目名','昨日','数值,创建时间',$CacheVal);
				TextDB_ChangeData('ForumCache','项目名','今日','数值,创建时间',$NewCacheVal);
			}
		}

		//更新最多发帖缓存
		if($CacheName=='最多发帖')
		{
			//获取今日帖子数
			$OldCache = TextDB_SearchData('ForumCache','项目名','今日');

			//如果帖子多于缓存中的记录，则更新
			if($CacheInfo[0]['数值']<$OldCache[0]['数值'])
			{
				$NewCacheVal = array($OldCache[0]['数值'],$OldCache[0]['创建时间']);
				TextDB_ChangeData('ForumCache','项目名','最多发帖','数值,创建时间',$NewCacheVal);
			}
		}

		//更新最高在线缓存
		if($CacheName=='最高在线' && !empty($CacheVal))
		{
			//如果在线人数多于缓存中的记录，则更新
			if($CacheInfo[0]["数值"]<$CacheVal)
			{
				$NewCacheVal = array($CacheVal,time());
				TextDB_ChangeData('ForumCache','项目名','最高在线','数值,创建时间',$NewCacheVal);
			}
		}

		//更新最新注册，会员数
		if($CacheName=='最新注册' and !empty($CacheVal))
		{
			$OldCache    = TextDB_SearchData('ForumCache','项目名','会员');
			$OldCacheVal = array($OldCache[0]['数值']+1,time());
			$NewCacheVal = array($CacheVal,time());
			TextDB_ChangeData('ForumCache','项目名','会员','数值,创建时间',$OldCacheVal);
			TextDB_ChangeData('ForumCache','项目名','最新注册','数值,创建时间',$NewCacheVal);
		}

		//更新最新注册，会员数
		if($CacheName=='删除会员')
		{
			$OldCache    = TextDB_SearchData('ForumCache','项目名','会员');
			$OldCacheVal = array($OldCache[0]['数值']-1,time());
			TextDB_ChangeData('ForumCache','项目名','会员','数值,创建时间',$OldCacheVal);
			if(!empty($CacheVal))
			{
				$OldCache = TextDB_SearchData('ForumCache','项目名','最新注册');
				if($CacheVal==$OldCache[0]['数值'])
				{
					$MemberInfo  = TextDB_SearchData('Members',NULL,NULL,'DESC',NULL,NULL,1);
					$Member      = $MemberInfo[0];
					$NewCacheVal = array($Member['0'].''.$Member['昵称'],time());
					TextDB_ChangeData('ForumCache','项目名','最新注册','数值,创建时间',$NewCacheVal);
				}
			}
		}

		//更新论坛缓存
		if($CacheName=='论坛' && !empty($CacheVal) && is_array($CacheVal))
		{
			//获取论坛缓存信息
			$OldCache   = TextDB_SearchData('Forum_B'.$CacheVal[0],'TEXTDB_HID',$CacheVal[1]);
			$MemberInfo = TextDB_SearchData('Members','昵称',_LoginName_);

			//如果更新内容是主题，则更新论坛缓存
			if($UpdateClass=='Topic')
			{
				TextDB_ChangeData('Forum_B'.$CacheVal[0],'TEXTDB_HID',$CacheVal[1],'主题数',$OldCache[0]['主题数']+1);
				TextDB_ChangeData('Members','昵称',_LoginName_,'积分',$MemberInfo[0]['积分']+_TopicAward_);
				UpdateCache('主题');
			}

			//如果更新内容是回复，则更新主题缓存
			if($UpdateClass=='Reply')
			{
				$OldCache2=TextDB_SearchData('Topic_B'.$CacheVal[0].'_F'.$CacheVal[1],'TEXTDB_HID',$CacheVal[2]);
				TextDB_ChangeData('Topic_B'.$CacheVal[0].'_F'.$CacheVal[1],'TEXTDB_HID',$CacheVal[2],'回复数',$OldCache2[0]['回复数']+1);
				TextDB_ChangeData('Members','昵称',_LoginName_,'积分',$MemberInfo[0]['积分']+_ReplyAward_);
			}

			//更新论坛帖子，今日帖数据
			TextDB_ChangeData('Forum_B'.$CacheVal[0],'TEXTDB_HID',$CacheVal[1],'帖子数',$OldCache[0]['帖子数']+1);
			TextDB_ChangeData('Forum_B'.$CacheVal[0],'TEXTDB_HID',$CacheVal[1],'今日帖子',$OldCache[0]['今日帖子']+1);

			//更新论坛缓存
			UpdateCache('帖子');
			UpdateCache('今日');

			//更新用户发帖缓存
			$MemberInfo = TextDB_SearchData('Members','昵称',_LoginName_);
			TextDB_ChangeData('Members','昵称',_LoginName_,'发帖数',$MemberInfo[0]['发帖数']+1);

			//检测&更新用户等级
			if($Level=CheckMemberLevel($MemberInfo[0]['发帖数']+1))
			{
				TextDB_ChangeData('Members','昵称',_LoginName_,'等级',$Level);
			}
		}

		//更新各种缓存,论坛数（只创建）
		if(($CacheName=='论坛' && empty($CacheVal)) || $CacheName=='主题' || $CacheName=='帖子' || $CacheName=='今日')
		{
			$NewCacheVal=array($CacheInfo[0]['数值']+1,time());
			TextDB_ChangeData('ForumCache','项目名',$CacheName,'数值,创建时间',$NewCacheVal);
			UpdateCache('最多发帖');
		}

		if($CacheName=='删除' && !empty($CacheVal))
		{
			$CacheInfo=TextDB_SearchData('ForumCache','项目名',$CacheVal);
			if($CacheInfo[0]['数值']>0)
			{
				$NewCacheVal=array($CacheInfo[0]['数值']-1,time());
				TextDB_ChangeData('ForumCache','项目名',$CacheVal,'数值,创建时间',$NewCacheVal);
			}
			UpdateCache('最多发帖');
		}
	}

	//更新论坛缓存
	function UpdateForumCache()
	{
		//获取板块信息
		$BoardInfo=TextDB_SearchData("Board");

		if($BoardInfo)
		{
			foreach($BoardInfo as $Board)
			{
				$BoradHID  = $Board[0];
				$ForumInfo = TextDB_SearchData("Forum_B".$BoradHID);
				if($ForumInfo)
				{
					foreach($ForumInfo as $Forum)
					{
						$ForumHID  = $Forum[0];
						$ForumName = $Forum["论坛名称"];

						//获取主题信息
						$TopicInfo = TextDB_SearchData("Topic_B".$BoradHID."_F".$ForumHID,null,null,'desc',null,0,1);
						if($TopicInfo)
						{
							//如果最后一个主题属于昨天
							if($TopicInfo[0]["创建时间"]<_NowTimes_)
							{
								//更新论坛缓存
								TextDB_ChangeData("Forum_B".$BoradHID,"TEXTDB_HID",$ForumHID,"今日帖子",0);
							}
						}
					}
				}
			}
		}
	}

	//检测用户邮件地址记录
	function CheckMemberEMail($EMail)
	{
		$MembersInfo = TextDB_SearchData("Members","帐号",$EMail);
		if($MembersInfo)
		{
			return true;
		}
		return false;
	}

	//检测用户密码记录
	function CheckMemberPasswd($EMail,$Passwd)
	{
		$MembersInfo = TextDB_SearchData("Members",array("帐号","密码"),array($EMail,md5($Passwd)));
		if($MembersInfo)
		{
			return true;
		}
		return false;
	}

	//检测用户昵称记录
	function CheckMemberFName($FName)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",$FName);
		if($MembersInfo)
		{
			return true;
		}
		return false;
	}

	//获取用户权限记录
	function CheckMemberJobs($FName)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",$FName);
		return $MembersInfo[0]["权限"];
	}

	//获取用户权限记录
	function CheckMemberSex($FName)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",$FName);
		return $MembersInfo[0]["性别"];
	}

	//获取用户等级
	function CheckMemberLevel($Topic)
	{
		$MemberLevel = explode(",",_MemberLevel_);
		if($MemberLevel)
		{
			foreach($MemberLevel as $LvID=>$Lv)
			{
				if($Topic==$Lv)
				{
					return $LvID+1;
				}
			}
		}
		return false;
	}

	//获取用户注册日期
	function GetMemberHID($FName)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",$FName);
		return $MembersInfo[0][0];
	}

	//获取用户注册日期
	function GetMemberREGDate($FName)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",$FName);
		return $MembersInfo[0]["注册日期"];
	}

	//增加用户记录
	function AddMember($MemberInfo)
	{
		TextDB_InsertData("Members","*",$MemberInfo);
		$MemberID = TextDB_GetTableTrueNum("Members");
		TextDB_CreateTable("MBox_M".$MemberID,_MBoxFields_);
		UpdateCache("最新注册",$MemberID."".$MemberInfo[2]);
	}

	//删除用户
	function DelMember($MemberID)
	{
		TextDB_DeleteData("Members","TEXTDB_HID",$MemberID);
		TextDB_DeleteTable("MBox_M".$MemberID);
	}

	//更新用户信息
	function UpdateMemberInfo($MemberName,$NewMemberInfo)
	{
		TextDB_ChangeData("Members","昵称",$MemberName,"*",$NewMemberInfo);
	}

	//检测好友数量
	function CheckFirNum($MemberName)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",$MemberName);
		$Member      = $MembersInfo[0];
		if(!empty($Member["好友"]))
		{
			return sizeof(explode(",",$Member["好友"]));
		}
		else
		{
			return false;
		}
	}

	//增加好友
	function AddFir($FirID)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",_LoginName_);
		$FirInfo     = TextDB_SearchData("Members","TEXTDB_HID",$FirID);
		$Member      = $MembersInfo[0];
		$Fir         = $FirInfo[0];
		if(!empty($Member["好友"]))
		{
			if(!empty($FirID))
			{
				if(!strstr($Member["好友"],$Fir["昵称"]))
				{
					$NewMemberFirInfo=$Member["好友"].",".$Fir[0]."".$Fir["昵称"];
				}
				else
				{
					ShowMegBox("好友已存在！",$_SERVER["HTTP_REFERER"],'goto');
				}
			}
			else
			{
				ShowMegBox("没有此用户。",$_SERVER["HTTP_REFERER"],'goto');
			}
		}
		else
		{
			$NewMemberFirInfo=$Fir[0]."".$Fir["昵称"];
		}
		if(TextDB_ChangeData("Members","昵称",_LoginName_,"好友",$NewMemberFirInfo))
		{
			ShowMegBox("好友添加成功！",$_SERVER["HTTP_REFERER"],'goto');
		}
	}

	//删除好友
	function DelFir($FirID)
	{
		$MembersInfo = TextDB_SearchData("Members","昵称",_LoginName_);
		$FirInfo     = TextDB_SearchData("Members","TEXTDB_HID",$FirID);
		$Member      = $MembersInfo[0];
		$Fir         = $FirInfo[0];
		if(!empty($Member["好友"]))
		{
			if(strstr($Member["好友"],","))
			{
				$NewMemberFirInfo = str_replace(",".$Fir[0]."".$Fir["昵称"],"",$Member["好友"]);
			}
			else
			{
				$NewMemberFirInfo = str_replace($Fir[0]."".$Fir["昵称"],"",$Member["好友"]);
			}

			if(TextDB_ChangeData("Members","昵称",_LoginName_,"好友",$NewMemberFirInfo))
			{
				ShowMegBox("好友删除成功！",$_SERVER["HTTP_REFERER"],'goto');
			}
		}
		else
		{
			ShowMegBox("您还没有添加好友！",$_SERVER["HTTP_REFERER"],'goto');
		}
	}

	//添加公告信息
	function AddAnno($AnnoInfo)
	{
		TextDB_InsertData("Announcements","*",$AnnoInfo);
	}

	//更新公告信息
	function UpdateAnno($AnnoID,$NewAnnoInfo)
	{
		TextDB_ChangeData("Announcements","TEXTDB_HID",$AnnoID,"*",$NewAnnoInfo);
	}

	//删除公告信息
	function DelAnno($AnnoID)
	{
		TextDB_DeleteData("Announcements","TEXTDB_HID",$AnnoID);
	}

	//添加文字链接
	function AddTextLink($TextLinkInfo)
	{
		TextDB_InsertData("TextLinks","*",$TextLinkInfo);
	}

	//更新文字链接
	function UpdateTextLink($LinkName,$NewTextLinkInfo)
	{
		TextDB_ChangeData("TextLinks","网站名称",$LinkName,"*",$NewTextLinkInfo);
	}

	//删除文字链接
	function DelTextLink($LinkName)
	{
		if(TextDB_SearchData("TextLinks","网站名称",$LinkName))
		{
			TextDB_DeleteData("TextLinks","网站名称",$LinkName);
		}
		else
		{

		}
	}

	//添加图片链接
	function AddPicLink($PicLinkInfo)
	{
		TextDB_InsertData("PicLinks","*",$PicLinkInfo);
	}

	//更新图片链接
	function UpdatePicLink($LinkName,$NewPicLinkInfo)
	{
		TextDB_ChangeData("PicLinks","网站名称",$LinkName,"*",$NewPicLinkInfo);
	}

	//删除图片链接
	function DelPicLink($LinkName)
	{
		TextDB_DeleteData("PicLinks","网站名称",$LinkName);
	}

	//发送信息
	function SendMBoxInfo($ToName,$MBoxInfo)
	{
		//如果含有多个用户名,切分成数组
		if(strstr($ToName,",")){ $ToName=explode(",",$ToName); }

		//如果多个用户
		if(is_array($ToName))
		{
			foreach($ToName as $Name)
			{
				//检测用户是否存在
				if(TextDB_CheckTable("MBox_M".GetMemberHID($Name)))
				{
					//存在，发送信息
					TextDB_InsertData("MBox_M".GetMemberHID($Name),"*",$MBoxInfo);
				}
				else
				{
					//不存在，列入失败名单
					$FailName.=$Name."\\n";
				}
			}

			if(!empty($FailName))
			{
				ShowMegBox("下列用户不存在，无法发送：\\n".$FailName."请检查，用户名是否正确。",$_SERVER["HTTP_REFERER"],'goto');
			}
			else
			{
				ShowMegBox("发送成功！",$_SERVER["HTTP_REFERER"],'goto');
			}
		}
		else //如果单个用户
		{
			if(TextDB_CheckTable("MBox_M".GetMemberHID($ToName)))
			{
				TextDB_InsertData("MBox_M".GetMemberHID($ToName),"*",$MBoxInfo);
				ShowMegBox("发送成功！",$_SERVER["HTTP_REFERER"],'goto');
			}
			else
			{
				ShowMegBox("发送失败！！\\n用户 [".$ToName."] 不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}
	}

	function ReadMBoxInfo($UID,$MBoxID)
	{
		//获取用户信息
		$MBoxInfo = TextDB_SearchData("MBox_M".$UID,"TEXTDB_HID",$MBoxID);
		TextDB_ChangeData("MBox_M".$UID,"状态",0);
	}

	function DelMBoxInfo($UID,$MBoxID)
	{
		TextDB_DeleteData("MBox_M".$UID,"TEXTDB_HID",$MBoxID);
		ShowMegBox("信息删除成功！","profile.php?action=mbox&uid=".$UID,'goto');
	}

	//增加分类记录
	function AddBoard($BoardInfo)
	{
		TextDB_InsertData("Board","*",$BoardInfo);
		$BoardID = TextDB_GetTableTrueNum("Board");
		TextDB_CreateTable("Forum_B{$BoardID}",_ForumFields_);
		TextDB_CreateTable("Board{$BoardID}_TopicList",_TopicListFields_);
		TextDB_CreateTable("Board{$BoardID}_ReplyList",_ReplyListFields_);
		TextDB_CreateTable("Board{$BoardID}_TRList",_TRListFields_);
	}

	//更新分类记录
	function UpdateBoardInfo($BoardID,$NewBoardInfo)
	{
		TextDB_ChangeData("Board","TEXTDB_HID",$BoardID,"*",$NewBoardInfo);
	}

	//删除板块
	function _DelBoard($BoardID)
	{
		if(!empty($BoardID))
		{
			$BoardInfo = TextDB_SearchData("Board","TEXTDB_HID",$BoardID);
			$root      = explode("",$BoardInfo[0]["SID管理员"]);

			if($root[0])
			{
				$MemberInfo = TextDB_SearchData("Members","昵称",$root[1]);
				TextDB_ChangeData("Members","昵称",$root[1],"权限",5);
			}

			TextDB_DeleteTable("Forum_B".$BoardID);
			TextDB_DeleteTable("Board{$BoardID}_TopicList");
			TextDB_DeleteTable("Board{$BoardID}_ReplyList");
			TextDB_DeleteTable("Board{$BoardID}_TRList");
			TextDB_DeleteData("Board","TEXTDB_HID",$BoardID);

			return true;
		}
		else
		{
			return false;
		}
	}

	//增加论坛记录
	function AddForum($BoardID,$ForumInfo)
	{
		TextDB_InsertData("Forum_B{$BoardID}","*",$ForumInfo);
		$ForumID = TextDB_GetTableTrueNum("Forum_B{$BoardID}");
		TextDB_CreateTable("Topic_B{$BoardID}_F{$ForumID}",_TopicFields_);
		TextDB_CreateTable("Forum{$ForumID}_ReplyList",_ReplyListFields_);
		TextDB_CreateTable("Forum{$ForumID}_TRList",_TRListFields_);
		UpdateCache("论坛");
	}

	//更新论坛记录
	function UpdateForumInfo($BoardID,$ForumID,$NewForumInfo)
	{
		TextDB_ChangeData("Forum_B{$BoardID}","TEXTDB_HID",$ForumID,"*",$NewForumInfo);
	}

	//删除论坛
	function _DelForum($BoardID,$ForumID)
	{
		if(!empty($BoardID) and !empty($ForumID))
		{
			$ForumInfo  = TextDB_SearchData("Forum_B".$BoardID,"TEXTDB_HID",$ForumID);
			$root       = explode("",$ForumInfo[0]["SID版主"]);

			if($root[0])
			{
				$MemberInfo = TextDB_SearchData("Members","昵称",$root[1]);
				TextDB_ChangeData("Members","昵称",$root[1],"权限",5);
			}

			TextDB_DeleteTable("Topic_B".$BoardID."_F".$ForumID);
			TextDB_DeleteTable("Forum{$ForumID}_ReplyList");
			TextDB_DeleteTable("Forum{$ForumID}_TRList");
			TextDB_DeleteData("Forum_B".$ReplyID,"TEXTDB_HID",$ReplyID);
			UpdateCache("删除","论坛");

			return true;
		}
		else
		{
			return false;
		}
	}

	//增加主题记录
	function AddTopic($BoardID,$ForumID,$TopicInfo)
	{
		TextDB_InsertData("Topic_B{$BoardID}_F{$ForumID}","*",$TopicInfo);
		$TopicID = TextDB_GetTableTrueNum("Topic_B{$BoardID}_F{$ForumID}");
		TextDB_CreateTable("Reply_B{$BoardID}_F{$ForumID}_T{$TopicID}",_ReplyFields_);
		UpdateCache("论坛",array($BoardID,$ForumID),"Topic");
		UpdateTRA('添加',$BoardID,$ForumID,$TopicID);
	}

	//更新主题记录
	function UpdateTopicInfo($BoardID,$ForumID,$TopicID,$NewTopicInfo)
	{
		TextDB_ChangeData("Topic_B".$BoardID."_F".$ForumID,"TEXTDB_HID",$TopicID,"*",$NewTopicInfo);
		UpdateTRA('更新',$BoardID,$ForumID,$TopicID);
	}

	//删除主题
	function _DelTopic($BoardID,$ForumID,$TopicID)
	{
		if(!empty($BoardID) and !empty($ForumID) and !empty($TopicID))
		{
			$ForumInfo  = TextDB_SearchData("Forum_B".$BoardID,"TEXTDB_HID",$ForumID);
			$TopicInfo  = TextDB_SearchData("Topic_B".$BoardID."_F".$ForumID,"TEXTDB_HID",$TopicID);
			$user       = explode("",$TopicInfo[0]["SID发表人"]);
			$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$user[0]);
			$times      = mktime(0,0,0,date('m',$TopicInfo[0]['创建时间']),date('d',$TopicInfo[0]['创建时间']),date('Y',$TopicInfo[0]['创建时间']));

			//如果回复属于今天
			if($times==_NowTimes_)
			{
				UpdateCache("删除","今日");
				TextDB_ChangeData("Forum_B".$BoardID,"TEXTDB_HID",$ForumID,"今日帖子",$ForumInfo[0]["今日帖子"]-1);
			}

			//如果回复属于昨天
			if($times==_LastTimes_)
			{
				UpdateCache("删除","昨日");
			}

			//删除回复表
			TextDB_DeleteTable("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID);

			//更新论坛帖子，今日帖数据
			TextDB_ChangeData("Forum_B".$BoardID,"TEXTDB_HID",$ForumID,"主题数,帖子数",array($ForumInfo[0]["主题数"]-1,$ForumInfo[0]["帖子数"]-1));
			TextDB_ChangeData("Members","TEXTDB_HID",$user[0],"积分,发帖数",array($MemberInfo[0]["积分"]-_TopicAward_,$MemberInfo[0]["发帖数"]-1));
			TextDB_DeleteData("Topic_B".$BoardID."_F".$ForumID,"TEXTDB_HID",$TopicID);
			UpdateCache("删除","主题");
			UpdateCache("删除","帖子");

			UpdateTRA('删除',$BoardID,$ForumID,$TopicID);

			return true;
		}
		else
		{
			return false;
		}
	}

	//增加帖子记录
	function AddReply($BoardID,$ForumID,$TopicID,$ReplyInfo)
	{
		TextDB_InsertData("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID,"*",$ReplyInfo);
		$ReplyID = TextDB_GetTableTrueNum("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID);
		UpdateCache("论坛",array($BoardID,$ForumID,$TopicID),"Reply");
		UpdateTRA('添加',$BoardID,$ForumID,$TopicID,$ReplyID);
	}

	//更新帖子记录
	function UpdateReplyInfo($BoardID,$ForumID,$TopicID,$ReplyID,$NewReplyInfo)
	{
		TextDB_ChangeData("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID,"TEXTDB_HID",$ReplyID,"*",$NewReplyInfo);
		UpdateTRA('更新',$BoardID,$ForumID,$TopicID,$ReplyID);
	}

	//删除回复帖子
	function _DelReply($BoardID,$ForumID,$TopicID,$ReplyID)
	{
		if(!empty($BoardID) and !empty($ForumID) and !empty($TopicID) and !empty($ReplyID))
		{
			$ForumInfo  = TextDB_SearchData("Forum_B".$BoardID,"TEXTDB_HID",$TopicID);
			$TopicInfo  = TextDB_SearchData("Topic_B".$BoardID."_F".$ForumID,"TEXTDB_HID",$TopicID);
			$ReplyInfo  = TextDB_SearchData("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID,"TEXTDB_HID",$ReplyID);
			$user       = explode("",$ReplyInfo[0]["SID答复人"]);
			$MemberInfo = TextDB_SearchData("Members","TEXTDB_HID",$user[0]);
			$times      = mktime(0,0,0,date('m',$ReplyInfo[0]['创建时间']),date('d',$ReplyInfo[0]['创建时间']),date('Y',$ReplyInfo[0]['创建时间']));

			//如果回复属于今天
			if($times==_NowTimes_)
			{
				UpdateCache("删除","今日");
				TextDB_ChangeData("Forum_B".$TopicID,"TEXTDB_HID",$TopicID,"今日帖子",$ForumInfo[0]["今日帖子"]-1);
			}

			//如果回复属于昨天
			if($times==_LastTimes_)
			{
				UpdateCache("删除","昨日");
			}

			//更新论坛帖子，今日帖数据
			TextDB_ChangeData("Forum_B".$BoardID,"TEXTDB_HID",$TopicID,"帖子数",$ForumInfo[0]["帖子数"]-1);
			TextDB_ChangeData("Topic_B".$BoardID."_F".$ForumID,"TEXTDB_HID",$TopicID,"回复数",$TopicInfo[0]["回复数"]-1);
			TextDB_ChangeData("Members","TEXTDB_HID",$user[0],"积分,发帖数",array($MemberInfo[0]["积分"]-_ReplyAward_,$MemberInfo[0]["发帖数"]-1));
			TextDB_DeleteData("Reply_B".$BoardID."_F".$ForumID."_T".$TopicID,"TEXTDB_HID",$ReplyID);

			UpdateCache("删除","帖子");

			UpdateTRA('删除',$BoardID,$ForumID,$TopicID,$ReplyID);

			return true;
		}
		else
		{
			return false;
		}
	}

	//论坛管理操作
	function ForumAdminAction()
	{
		//更新论坛基本设置
		if(isset($_POST["UpdateConfig"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法更新论坛基本设置！",$_SERVER["HTTP_REFERER"],'goto');
			}

			$OPN[] = "论坛名称";
			$OPC[] = $_POST["ForumTitle"];
			$OPN[] = "论坛描述";
			$OPC[] = $_POST["ForumDescription"];
			$OPN[] = "关键词汇";
			$OPC[] = $_POST["ForumKeywords"];

			$OPN[] = "论坛路径";
			$OPC[] = $_POST["ForumUrl"];
			$OPN[] = "备案序号";
			$OPC[] = $_POST["ForumICP"];
			$OPN[] = "开设年份";
			$OPC[] = $_POST["ForumCreateDate"];

			$OPN[] = "友情链接";
			$OPC[] = $_POST["LinkDisplay"];
			$OPN[] = "在线情况";
			$OPC[] = $_POST["OnlineDisplay"];
			$OPN[] ="统计时间";
			$OPC[] = $_POST["StatTime"];

			$OPN[] = "注册时限";
			$OPC[] = $_POST["REGTime"];
			$OPN[] = "会员信息";
			$OPC[] = $_POST["MemberInfoDisply"];
			$OPN[] = "等级设置";
			$OPC[] = $_POST["MemberLevel"];

			$OPN[] = "发帖得分";
			$OPC[] = $_POST["TopicAward"];
			$OPN[] = "回复得分";
			$OPC[] = $_POST["ReplyAward"];

			$OPN[] = "发信息得分";
			$OPC[] = $_POST["SendInfoAward"];
			$OPN[] = "每日信息数";
			$OPC[] = $_POST["DayInfoNumber"];
			$OPN[] = "最大信息数";
			$OPC[] = $_POST["MaxInfoNumber"];

			$OPN[] = "默认皮肤";
			$OPC[] = $_POST["SkinName"];

			if(!is_dir('Skin/'.$_POST["SkinName"]))
			{
				ShowMegBox("您设置的皮肤【{$_POST['SkinName']}】不存在！",$_SERVER["HTTP_REFERER"],'back');
			}

			foreach($OPN as $K=>$N)
			{
				TextDB_ChangeData("Config","项目名",$N,"内容",$OPC[$K]);
			}

			ShowMegBox("基本设置修改成功！",$_SERVER["HTTP_REFERER"],'goto');
		}


		//设置管理员&超版权限
		if(isset($_POST["setAdmin"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法设置会员权限！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if((($_POST['class_m']==5 || $_POST['class_m']==2) && !CheckForumAdminNum($_POST['class_mn'])) || CheckMemberJobs($_POST['class_mn'])==3 || CheckMemberJobs($_POST['class_mn'])==4)
			{
				if(CheckMemberJobs($_POST["class_mn"])==3 || CheckMemberJobs($_POST["class_mn"])==4)
				{
					ShowMegBox("会员 [".$_POST["class_mn"]."] 已经拥有是区版主，或者版主\\n设置请先取消他们的职位。",$_SERVER["HTTP_REFERER"],'back');
				}
				else
				{
					ShowMegBox("论坛至少需要一位管理员！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				TextDB_ChangeData("Members","昵称",$_POST["class_mn"],"权限",$_POST["class_m"]);
				if($_POST["class_m"]==1)
				{
					ShowMegBox("管理员 [".$_POST["class_mn"]."] 设置成功。",$_SERVER["HTTP_REFERER"],'goto');
				}
				elseif($_POST["class_m"]==2)
				{
					ShowMegBox("超级版主 [".$_POST["class_mn"]."] 设置成功。",$_SERVER["HTTP_REFERER"],'goto');
				}
				else
				{
					ShowMegBox("会员 [".$_POST["class_mn"]."] 管理权限取消。",$_SERVER["HTTP_REFERER"],'goto');
				}
			}
		}

		//如果增添板块
		if(isset($_POST['addBoard']))
		{
			if(!CheckForumAdmin() && !CheckForumRoot())
			{
				ShowMegBox('您的权限不足，无法添加新板块！',$_SERVER["HTTP_REFERER"],'goto');
			}

			if(empty($_POST['root_b']) || CheckMemberFName($_POST['root_b']))
			{
				//分类名称,分类描述,论坛个数,SID管理员,创建时间
				if(empty($_POST['root_b']))
				{
					$_POST['root_b']='0暂无';
				}
				else
				{
					$MemberInfo = TextDB_SearchData('Members','昵称',$_POST['root_b']);
					if($MemberInfo[0]['权限']==5)
					{
						$_POST['root_b'] = md5($_POST['root_b']).''.$_POST['root_b'];
						TextDB_ChangeData('Members','昵称',$_POST['root_b'],'权限',3);
					}
					else
					{
						ShowMegBox('授权用户，所属岗位必须是普通用户。',$_SERVER["HTTP_REFERER"],'back');
						return false;
					}
				}
				$BoardInfo = array(stripslashes($_POST['name_b']),stripslashes($_POST['alt_b']),0,$_POST['root_b'],time());
				AddBoard($BoardInfo);
				ShowMegBox('分类建立成功！',$_SERVER["HTTP_REFERER"],'goto');
			}
			else
			{
				ShowMegBox('分类授权人，昵称不存在！',$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//板块修改
		if(isset($_POST["editBoard"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']))
			{
				ShowMegBox("您的权限不足，无法进行板块修改！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST['BoardID']))
			{
				if(empty($_POST["root_b"]) || CheckMemberFName($_POST["root_b"]))
				{
					//分类名称,分类描述,论坛个数,SID管理员,创建时间
					if(empty($_POST["root_b"]))
					{
						$_POST["root_b"] = "0暂无";
					}
					else
					{
						$MemberInfo=TextDB_SearchData("Members","昵称",$_POST["root_b"]);
						if($MemberInfo[0]["权限"]==5)
						{
							$NewRoot         = $_POST["root_b"];
							$_POST["root_b"] = $MemberInfo[0][0]."".$_POST["root_b"];
						}
						else
						{
							ShowMegBox("授权用户，所属岗位必须是普通用户。",$_SERVER["HTTP_REFERER"],'goto');
							return false;
						}
					}
					$B_ID      = $_POST[BoardID];
					$BoardInfo = TextDB_SearchData("Board","TEXTDB_HID",$B_ID);  //获取子板块信息
					$root      = explode("",$BoardInfo[0]["SID管理员"]);

					if($root[0])
					{
						$MemberInfo = TextDB_SearchData("Members","昵称",$root[1]);
						TextDB_ChangeData("Members","昵称",$root[1],"权限",5);
					}

					TextDB_ChangeData("Members","昵称",$NewRoot,"权限",3);
					$NewBoardInfo = array(stripslashes($_POST["name_b"]),stripslashes($_POST["alt_b"]),0,$_POST["root_b"],time());
					UpdateBoardInfo($BoardInfo[0][0],$NewBoardInfo);
					ShowMegBox("分类修改成功！",$_SERVER["HTTP_REFERER"],'goto');
				}
				else
				{
					ShowMegBox("分类授权人，昵称不存在！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//删除板块
		if(isset($_POST["delBoard"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot())
			{
				ShowMegBox("您的权限不足，无法删除板块！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST['BoardID']))
			{
				$B_ID      = $_POST['BoardID'];
				$BoardInfo = TextDB_SearchData("Board","TEXTDB_HID",$B_ID);  //获取子板块信息
				$ForumInfo = TextDB_SearchData("Forum_B".$B_ID);
				if($ForumInfo)
				{
					foreach($ForumInfo as $Forum)
					{
						$F_ID      = $Forum['0'];
						$TopicInfo = TextDB_SearchData("Topic_B".$B_ID."_F".$F_ID);
						if($TopicInfo)
						{
							foreach($TopicInfo as $Topic)
							{
								$T_ID      = $Topic[0];
								$ReplyInfo = TextDB_SearchData("Reply_B".$B_ID."_F".$F_ID."_T".$T_ID);
								if($ReplyInfo)
								{
									foreach($ReplyInfo as $Reply)
									{
										$R_ID = $Reply['0'];
										_DelReply($B_ID,$F_ID,$T_ID,$R_ID);
									}
								}
								_DelTopic($B_ID,$F_ID,$T_ID);
							}
						}
						_DelForum($B_ID,$F_ID);
					}
				}
				_DelBoard($B_ID);
				ShowMegBox("分类删除成功！",'index.php','goto');
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//如果增添论坛
		if(isset($_POST["addForum"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']))
			{
				ShowMegBox("您的权限不足，无法添加论坛！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(empty($_POST["root_f"]))
			{
				$_POST["root_f"] = "0暂无";
			}
			else
			{
				$MemberInfo = TextDB_SearchData("Members","昵称",$_POST["root_f"]);

				if(!$MemberInfo)
				{
					ShowMegBox("论坛授权人，不存在！",$_SERVER["HTTP_REFERER"],'back');
					return false;
				}

				if($MemberInfo[0]["权限"]==5)
				{
					$_POST["root_f"] = md5($_POST["root_f"])."".$_POST["root_f"];
					TextDB_ChangeData("Members","昵称",$_POST["root_f"],"权限",4);
				}
				else
				{
					ShowMegBox("授权用户，所属岗位必须是普通用户。",$_SERVER["HTTP_REFERER"],'back');
					return false;
				}
			}
			$ForumInfo = array(stripslashes($_POST["name_f"]),stripslashes($_POST["alt_f"]),$_POST["mode_f"],$_POST["root_f"],0,0,0,time());
			AddForum($_POST["BoardID"],$ForumInfo);
			ShowMegBox("论坛建立成功！",$_SERVER["HTTP_REFERER"],'goto');
		}

		//修改论坛
		if(isset($_POST["editForum"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']) && !CheckRoot($_POST['BoardID'],$_POST['ForumID']))
			{
				ShowMegBox("您的权限不足，无法进行论坛修改！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST['BoardID']))
			{
				if(!empty($_POST['ForumID']))
				{
					if(empty($_POST["root_f"]) || CheckMemberFName($_POST["root_f"]))
					{
						if(empty($_POST["root_f"]))
						{
							$_POST["root_f"] = "0暂无";
						}
						else
						{
							$MemberInfo = TextDB_SearchData("Members","昵称",$_POST["root_f"]);
							if($MemberInfo[0]["权限"]==5)
							{
								$NewRoot         = $_POST["root_f"];
								$_POST["root_f"] = $MemberInfo[0][0]."".$_POST["root_f"];
							}
							else
							{
								ShowMegBox("一个授权人，只能管理一个板块。",$_SERVER["HTTP_REFERER"],'back');
								return false;
							}
						}

						$B_ID      = $_POST[BoardID];
						$F_ID      = $_POST[ForumID];
						$ForumInfo = TextDB_SearchData("Forum_B".$B_ID,"TEXTDB_HID",$F_ID);
						$root      = explode("",$ForumInfo[0]["SID版主"]);

						if($root[0])
						{
							$MemberInfo = TextDB_SearchData("Members","昵称",$root[1]);
							TextDB_ChangeData("Members","昵称",$root[1],"权限",5);
						}

						TextDB_ChangeData("Members","昵称",$NewRoot,"权限",4);
						$NewForumInfo = array(stripslashes($_POST["name_f"]),stripslashes($_POST["alt_f"]),$_POST["mode_f"],$_POST["root_f"],$ForumInfo[0]["主题数"],$ForumInfo[0]["帖子数"],$ForumInfo[0]["今日帖子"],$ForumInfo[0]["创建时间"]);
						UpdateForumInfo($B_ID,$F_ID,$NewForumInfo);
						ShowMegBox("分类修改成功！","viewforum.php?bid=".$B_ID."&fid=".$F_ID,'goto');
					}
					else
					{
						ShowMegBox("论坛授权人，昵称不存在！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("论坛ID不存在！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}


		//删除论坛
		if(isset($_POST["delForum"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']))
			{
				ShowMegBox("您的权限不足，无法删除论坛！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST[BoardID]))
			{
				if(!empty($_POST[ForumID]))
				{
					$B_ID      = $_POST[BoardID];
					$F_ID      = $_POST[ForumID];
					$TopicInfo = TextDB_SearchData("Topic_B".$B_ID."_F".$F_ID);
					if($TopicInfo)
					{
						foreach($TopicInfo as $Topic)
						{
							$T_ID      = $Topic['0'];
							$ReplyInfo = TextDB_SearchData("Reply_B".$B_ID."_F".$F_ID."_T".$T_ID);
							if($ReplyInfo)
							{
								foreach($ReplyInfo as $Reply)
								{
									$R_ID = $Reply['0'];
									_DelReply($B_ID,$F_ID,$T_ID,$R_ID);
								}
							}
							_DelTopic($B_ID,$F_ID,$T_ID);
						}
					}
					_DelForum($B_ID,$F_ID);
					ShowMegBox("论坛删除成功！","viewboard.php?bid=".$B_ID,'goto');
				}
				else
				{
					ShowMegBox("论坛ID不存在！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//增加主题
		if(isset($_POST["addTopic"]))
		{
			if(_UserLogin_)
			{
				if(strlen($_POST["title"])<=32 and strlen($_POST["title"])>=3)
				{
					$B_ID      = $_POST[BoardID];
					$F_ID      = $_POST[ForumID];
					$TopicInfo = array(stripslashes($_POST["title"]),stripslashes($_POST["content"]),0,_LoginID_.""._LoginName_,GetClinetIP(),"0暂无","","",0,0,time());
					AddTopic($B_ID,$F_ID,$TopicInfo);
					ShowMegBox("主题发表成功！",$_SERVER["HTTP_REFERER"],'goto');
				}
				else
				{
					ShowMegBox("标题长度只能是3-32字符（中文占2个字符）！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("请先登录！",$_SERVER["HTTP_REFERER"],'goto');
			}
		}

		//修改主题
		if(isset($_POST["editTopic"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']) && !CheckRoot($_POST['BoardID'],$_POST['ForumID']) && !CheckTopicRoot($_POST['BoardID'],$_POST['ForumID'],$_POST['TopicID']))
			{
				ShowMegBox("您的权限不足，无法进行主题修改！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST['BoardID']))
			{
				if(!empty($_POST['ForumID']))
				{
					if(!empty($_POST['TopicID']))
					{
						$B_ID         = $_POST[BoardID];
						$F_ID         = $_POST[ForumID];
						$T_ID         = $_POST[TopicID];
						$TopicInfo    = TextDB_SearchData("Topic_B".$B_ID."_F".$F_ID);
						$Topic        = $TopicInfo[0];
						$NewTopicInfo = array(stripslashes($_POST["title_t"]),stripslashes($_POST["content_t"]),$Topic["模式"],$Topic["SID发表人"],$Topic["发表IP"],_LoginID_.""._LoginName_,GetClinetIP(),time(),$Topic["回复数"],$Topic["浏览数"],$Topic["创建时间"]);
						UpdateTopicInfo($B_ID,$F_ID,$T_ID,$NewTopicInfo);
						ShowMegBox("主题修改成功！","viewtopic.php?bid=".$B_ID."&fid=".$F_ID."&tid=".$T_ID,'goto');
					}
					else
					{
						ShowMegBox("主题ID不存在！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("论坛ID不存在！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//删除主题
		if(isset($_POST["delTopic"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']) && !CheckRoot($_POST['BoardID'],$_POST['ForumID']) && !CheckTopicRoot($_POST['BoardID'],$_POST['ForumID'],$_POST['TopicID']))
			{
				ShowMegBox("您的权限不足，无法删除主题！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST[BoardID]))
			{
				if(!empty($_POST[ForumID]))
				{
					if(!empty($_POST[TopicID]))
					{
						$B_ID      = $_POST[BoardID];
						$F_ID      = $_POST[ForumID];
						$T_ID      = $_POST[TopicID];
						$ReplyInfo = TextDB_SearchData("Reply_B".$B_ID."_F".$F_ID."_T".$T_ID);
						if($ReplyInfo)
						{
							foreach($ReplyInfo as $Reply)
							{
								$R_ID = $Reply[0];
								_DelReply($B_ID,$F_ID,$T_ID,$R_ID);
							}
						}
						_DelTopic($B_ID,$F_ID,$T_ID);
						ShowMegBox("主题删除成功！","viewforum.php?bid=".$B_ID."&fid=".$F_ID,'goto');
					}
					else
					{
						ShowMegBox("主题ID不存在！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("论坛ID不存在！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//增加回复
		if(isset($_POST["addReply"]))
		{
			if(_UserLogin_)
			{
				$B_ID      = $_POST[BoardID];
				$F_ID      = $_POST[ForumID];
				$T_ID      = $_POST[TopicID];
				$ReplyInfo = array(stripslashes($_POST["content"]),0,_LoginID_.""._LoginName_,GetClinetIP(),"0暂无","","",time());
				AddReply($B_ID,$F_ID,$T_ID,$ReplyInfo);
				ShowMegBox("回复成功！",$_SERVER["HTTP_REFERER"],'goto');
			}
			else
			{
				ShowMegBox("请先登录！",$_SERVER["HTTP_REFERER"],'goto');
			}
		}

		//修改回复
		if(isset($_POST["editReply"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']) && !CheckRoot($_POST['BoardID'],$_POST['ForumID']) && !CheckTopicRoot($_POST['BoardID'],$_POST['ForumID'],$_POST['TopicID']) && !CheckReplyRoot($_POST['BoardID'],$_POST['ForumID'],$_POST['TopicID'],$_POST['ReplyID']))
			{
				ShowMegBox("您的权限不足，无法修改回复！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST['BoardID']))
			{
				if(!empty($_POST['ForumID']))
				{
					if(!empty($_POST['TopicID']))
					{
						if(!empty($_POST['ReplyID']))
						{
							if($_POST["content_r"])
							{
								$B_ID         = $_POST[BoardID];
								$F_ID         = $_POST[ForumID];
								$T_ID         = $_POST[TopicID];
								$R_ID         = $_POST[ReplyID];
								$ReplyInfo    = TextDB_SearchData("Reply_B".$B_ID."_F".$F_ID."_T".$T_ID,"TEXTDB_HID",$R_ID);
								$Reply        = $ReplyInfo[0];
								$NewReplyInfo = array(stripslashes($_POST["content_r"]),$Reply["模式"],$Reply["SID答复人"],$Reply["答复IP"],_LoginID_.""._LoginName_,GetClinetIP(),time(),$Reply["创建时间"]);
								UpdateReplyInfo($B_ID,$F_ID,$T_ID,$R_ID,$NewReplyInfo);
								ShowMegBox("回复修改成功！",$_SERVER["HTTP_REFERER"],'goto');
							}
							else
							{
								ShowMegBox("回复内容不能填空！",$_SERVER["HTTP_REFERER"],'back');
							}
						}
						else
						{
							ShowMegBox("回复ID不存在！",$_SERVER["HTTP_REFERER"],'back');
						}
					}
					else
					{
						ShowMegBox("主题ID不存在！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("论坛ID不存在！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//删除回复
		if(isset($_POST["delReply"]))
		{
			if(!CheckForumAdmin() && !CheckForumRoot() && !CheckBoardRoot($_POST['BoardID']) && !CheckRoot($_POST['BoardID'],$_POST['ForumID']) && !CheckTopicRoot($_POST['BoardID'],$_POST['ForumID'],$_POST['TopicID']) && !CheckReplyRoot($_POST['BoardID'],$_POST['ForumID'],$_POST['TopicID'],$_POST['ReplyID']))
			{
				ShowMegBox("您的权限不足，无法删除回复！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST['BoardID']))
			{
				if(!empty($_POST['ForumID']))
				{
					if(!empty($_POST['TopicID']))
					{
						if(!empty($_POST['ReplyID']))
						{
							$B_ID = $_POST[BoardID];
							$F_ID = $_POST[ForumID];
							$T_ID = $_POST[TopicID];
							$R_ID = $_POST[ReplyID];
							_DelReply($B_ID,$F_ID,$T_ID,$R_ID);
							ShowMegBox("回复删除成功！",$_SERVER["HTTP_REFERER"],'goto');
						}
						else
						{
							ShowMegBox("回复ID不存在！",$_SERVER["HTTP_REFERER"],'back');
						}
					}
					else
					{
						ShowMegBox("主题ID不存在！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("论坛ID不存在！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("分类ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//添加公告
		if(isset($_POST["addAnno"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法添加公告！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST["title_anno"]))
			{
				if(!empty($_POST["content_anno"]))
				{
					$AnnoInfo = array(stripslashes($_POST["title_anno"]),stripslashes($_POST["content_anno"]),_LoginID_.""._LoginName_,time());
					AddAnno($AnnoInfo);
					ShowMegBox("公告添加成功！",$_SERVER["HTTP_REFERER"],'goto');
				}
				else
				{
					ShowMegBox("公告内容不能为空！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("公告标题不能为空！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//修改 公告
		if(isset($_POST["editAnno"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法修改公告！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST["AnnoID"]))
			{
				if(!empty($_POST["title_anno"]))
				{
					if(!empty($_POST["content_anno"]))
					{
						$NewAnnoInfo = array(stripslashes($_POST["title_anno"]),stripslashes($_POST["content_anno"]),_LoginID_.""._LoginName_,time());
						UpdateAnno($_POST["AnnoID"],$NewAnnoInfo);
						ShowMegBox("公告修改成功！",$_SERVER["HTTP_REFERER"],'goto');
					}
					else
					{
						ShowMegBox("公告内容不能为空！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("公告标题不能为空！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			else
			{
				ShowMegBox("公告ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//删除 公告
		if(isset($_POST["delAnno"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法删除公告！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST["AnnoID"]))
			{
				DelAnno($_POST["AnnoID"]);
				ShowMegBox("公告删除成功！",$_SERVER["HTTP_REFERER"],'goto');
			}
			else
			{
				ShowMegBox("公告ID不存在！",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//删除会员
		if(isset($_POST["ProFileDel"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法删除会员！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!empty($_POST["UID"]))
			{
				$MembersInfo = TextDB_SearchData("Members","TEXTDB_HID",$_POST["UID"]);
				DelMember($_POST["UID"]);
				UpdateCache("删除会员",$_POST["UID"]."".$MembersInfo[0]["昵称"]);
				ShowMegBox("会员删除成功。",'profile.php?action=list','goto');
			}
			else
			{
				ShowMegBox("看到此提示，请查询以下两点：\\n1、您的帐户是否属于管理员\\n2、删除帐户的ID是否正确",$_SERVER["HTTP_REFERER"],'back');
			}
		}

		//添加连接
		if(isset($_POST["addLink"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法添加链接！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if($_POST["class_l"]==0 or $_POST["class_l"]==2)
			{
				if(!empty($_POST["name_l"]))
				{
					if(!empty($_POST["url_l"]))
					{
						$TextLinkInfo = array(stripslashes($_POST["name_l"]),stripslashes($_POST["alt_l"]),$_POST["url_l"]);
						AddTextLink($TextLinkInfo);
					}
					else
					{
						ShowMegBox("链接地址不能为空！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("链接名称不能为空！",$_SERVER["HTTP_REFERER"],'back');
				}
			}

			if($_POST["class_l"]==1 or $_POST["class_l"]==2)
			{
				if(!empty($_POST["name_l"]))
				{
					if(!empty($_POST["img_l"]))
					{
						if(!empty($_POST["url_l"]))
						{
							$PicLinkInfo = array(stripslashes($_POST["name_l"]),stripslashes($_POST["alt_l"]),$_POST["img_l"],$_POST["url_l"]);
							AddPicLink($PicLinkInfo);
						}
						else
						{
							ShowMegBox("链接地址不能为空！",$_SERVER["HTTP_REFERER"],'back');
						}
					}
					else
					{
						ShowMegBox("图片地址不能为空！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("链接名称不能为空！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			ShowMegBox("链接添加成功！",$_SERVER["HTTP_REFERER"],'goto');
		}

		if(isset($_POST["editLink"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法修改链接！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!$_POST["class_l"] || $_POST["class_l"]==2)
			{
				if(!empty($_POST["name_l"]))
				{
					if(!empty($_POST["url_l"]))
					{
						$NewTextLinkInfo = array(stripslashes($_POST["name_l"]),stripslashes($_POST["alt_l"]),$_POST["url_l"]);
						UpdateTextLink($_POST["name_l"],$NewTextLinkInfo);
					}
					else
					{
						ShowMegBox("链接地址不能为空！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("链接名称不能为空！",$_SERVER["HTTP_REFERER"],'back');
				}
			}

			if($_POST["class_l"] || $_POST["class_l"]==2)
			{
				if(!empty($_POST["name_l"]))
				{
					if(!empty($_POST["img_l"]))
					{
						if(!empty($_POST["url_l"]))
						{
							$NewPicLinkInfo = array(stripslashes($_POST["name_l"]),stripslashes($_POST["alt_l"]),$_POST["img_l"],$_POST["url_l"]);
							UpdatePicLink($_POST["name_l"],$NewPicLinkInfo);
						}
						else
						{
							ShowMegBox("链接地址不能为空！",$_SERVER["HTTP_REFERER"],'back');
						}
					}
					else
					{
						ShowMegBox("图片地址不能为空！",$_SERVER["HTTP_REFERER"],'back');
					}
				}
				else
				{
					ShowMegBox("链接名称不能为空！",$_SERVER["HTTP_REFERER"],'back');
				}
			}
			ShowMegBox("链接修改成功！",$_SERVER["HTTP_REFERER"],'goto');
		}

		if(isset($_POST["delLink"]))
		{
			if(!CheckForumAdmin())
			{
				ShowMegBox("您的权限不足，无法删除链接！",$_SERVER["HTTP_REFERER"],'goto');
			}

			if(!$_POST["class_l"] || $_POST["class_l"]==2)
			{
				if(!empty($_POST["name_l"]))
				{
					DelTextLink($_POST["name_l"]);
				}
				else
				{
					ShowMegBox('链接名称不能为空！',$_SERVER["HTTP_REFERER"],'back');
				}
			}

			if($_POST["class_l"] || $_POST["class_l"]==2)
			{
				if(!empty($_POST["name_l"]))
				{
					DelPicLink($_POST["name_l"]);
				}
				else
				{
					ShowMegBox('链接名称不能为空！',$_SERVER["HTTP_REFERER"],'back');
				}
			}
			ShowMegBox('链接删除成功！',$_SERVER["HTTP_REFERER"],'goto');
		}
	}

	//清除过期在线记录
	function CleanOnlineSave()
	{
		$OnlineInfo = TextDB_SearchData("OnlineInfo");
		if($OnlineInfo)
		{
			UpdateCache("最高在线",count($OnlineInfo));
			if($OnlineInfo)
			{
				foreach($OnlineInfo as $OI)
				{
					if((date("U")-$OI["创建时间"])>=(_StatTime_*60))
					{
						TextDB_DeleteData("OnlineInfo","认证号",$OI["认证号"]);
					}
				}
			}
		}
	}

	//检测是否在线
	function CheckOnline($FName)
	{
		$OnlineInfo = TextDB_SearchData("OnlineInfo","名称",$FName);
		if($OnlineInfo)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	//清除过期验证码记录
	function CleanSC()
	{
		$SCInfo = TextDB_SearchData("SecurityCode");
		if($SCInfo)
		{
			foreach($SCInfo as $SCI)
			{
				if((date("U")-$SCI["创建时间"])>=(_REGTime_*60))
				{
					TextDB_DeleteData("SecurityCode","认证号",$SCI["认证号"]);
				}
			}
		}
	}

	//检测验证码记录
	function CheckSC($SID,$YZM)
	{
		$SCInfo = TextDB_SearchData("SecurityCode");
		if($SCInfo)
		{
			foreach($SCInfo as $SCI)
			{
				if($SCI["认证号"]==$SID && $SCI["验证数字"]==$YZM)
				{
					return true;
				}
			}
		}
		return false;
	}

	//阿拉伯转中文
	function NumToChinese($LowNum)
	{
		//强制转化为字符串类型
		$LowNum = (string)$LowNum;
		//获取字符串长度
		$Length  =strlen($LowNum);

		//获取大小写中文数字
		$Sim = explode(",",_SimNumber_);
		$Cap = explode(",",_CapNumber_);

		//更换为中文数字
		for($i=0;$i<$Length;$i++)
		{
			if(rand(0,1))
			{
				//更换为大写
				$CNum.=$Cap[$LowNum[$i]];
			}
			else
			{
				//更换为小写
				$CNum.=$Sim[$LowNum[$i]];
			}
		}
		return $CNum;
	}

	//优化创建目录函数
	function CreatDir($DirFileName)
	{
		if(file_exists($DirFileName))
		{
			if(!is_dir($DirFileName))
			{
				unlink($DirFileName);
				mkdir($DirFileName, 0777);
			}
		}
		else
		{
			mkdir($DirFileName, 0777);
		}
	}

	//优化创建文件函数
	function CreatFile($FileName)
	{
		if(file_exists($FileName))
		{
			if(is_dir($FileName))
			{
				rmdir($FileName);
				touch($FileName);
				chmod($FileName,0777);
			}
		}
		else
		{
			touch($FileName);
			chmod($FileName,0777);
		}
	}

	//获取客户端IP
	function GetClinetIP()
	{
		static $ClinetIP;
		if(isset($_SERVER))
		{
			if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
			{
				$ClinetIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
			}
			elseif(isset($_SERVER["HTTP_CLIENT_IP"]))
			{
				$ClinetIP = $_SERVER["HTTP_CLIENT_IP"];
			}
			else
			{
				$ClinetIP = $_SERVER["REMOTE_ADDR"];
			}
		}
		else
		{
			if(getenv("HTTP_X_FORWARDED_FOR"))
			{
				$ClinetIP = getenv("HTTP_X_FORWARDED_FOR");
			}
			elseif(getenv("HTTP_CLIENT_IP"))
			{
				$ClinetIP = getenv("HTTP_CLIENT_IP");
			}
			else
			{
				$ClinetIP = getenv("REMOTE_ADDR");
			}
		}
		return $ClinetIP;
	}

	//获取用户操作系统
	function GetClinetOS()
	{
		$OS="未知操作系统";
		$Agent=$_SERVER["HTTP_USER_AGENT"];
		if(stristr($Agent,"win")!=false and stristr($Agent,"95")!=false)
		{
			$OS="Windows 95";
		}
		elseif(stristr($Agent,"win 9x")!=false and stristr($Agent,"4.90")!=false)
		{
			$OS="Windows Me";
		}
		elseif(stristr($Agent,"win")!=false and stristr($Agent,"98")!=false)
		{
			$OS="Windows 98";
		}
		elseif(stristr($Agent,"win")!=false and stristr($Agent,"nt 5.2")!=false)
		{
			$OS="Windows 2003";
		}
		elseif(stristr($Agent,"win")!=false and stristr($Agent,"nt 5.1")!=false)
		{
			$OS="Windows XP";
		}
		elseif(stristr($Agent,"win")!=false and stristr($Agent,"nt 5.0")!=false)
		{
			$OS="Windows 2000";
		}
		elseif(stristr($Agent,"win")!=false and stristr($Agent,"nt")!=false)
		{
			$OS="Windows NT";
		}
		elseif(stristr($Agent,"win")!=false and stristr($Agent,"32")!=false)
		{
			$OS="Windows 32";
		}
		elseif(stristr($Agent,"win")!=false)
		{
			$OS="Windows";
		}
		elseif(stristr($Agent,"linux")!=false)
		{
			$OS="Linux";
		}
		elseif(stristr($Agent,"unix")!=false)
		{
			$OS="UNIX";
		}
		elseif(stristr($Agent,"sun")!=false and stristr($Agent,"os")!=false)
		{
			$OS="SUN OS";
		}
		elseif(stristr($Agent,"ibm")!=false and stristr($Agent,"os")!=false)
		{
			$OS="IBM OS";
		}
		elseif(stristr($Agent,"Mac")!=false and stristr($Agent,"PC")!=false)
		{
			$OS="MAC OS";
		}
		elseif(stristr($Agent,"PowerPC")!=false)
		{
			$OS="PowerPC";
		}
		elseif(stristr($Agent,"AIX")!=false)
		{
			$OS="AIX";
		}
		elseif(stristr($Agent,"HPUX")!=false)
		{
			$OS="HPUX";
		}
		elseif(stristr($Agent,"NetBSD")!=false)
		{
			$OS="NetBSD";
		}
		elseif(stristr($Agent,"BSD")!=false)
		{
			$OS="BSD";
		}
		elseif(stristr($Agent,"OSF1")!=false)
		{
			$OS="OSF1";
		}
		elseif(stristr($Agent,"IRIX")!=false)
		{
			$OS="IRIX";
		}
		elseif(stristr($Agent,"FreeBSD")!=false)
		{
			$OS="FreeBSD";
		}
		elseif(stristr($Agent,"googlebot")!=false)
		{
			$OS="谷歌";
		}
		elseif(stristr($Agent,"slurp")!=false)
		{
			$OS="雅虎";
		}
		elseif(stristr($Agent,"baiduspider")!=false)
		{
			$OS="百度";
		}
		elseif(stristr($Agent,"iaskspider")!=false)
		{
			$OS="爱问";
		}
		if($OS=="")
		{
			$OS="未知操作系统";
		}
		return $OS;
	}

	//获取用户浏览器
	function GetClinetBrowser()
	{
		$Browser="未知浏览器";
		$Agent=$_SERVER["HTTP_USER_AGENT"];
		if(stristr($Agent,"MSIE 7")!=false)
		{
			$Browser="Internet Explorer 7";
		}
		elseif(stristr($Agent,"MSIE 6")!=false)
		{
			$Browser="Internet Explorer 6";
		}
		elseif(stristr($Agent,"MSIE 5.5")!=false)
		{
			$Browser="Internet Explorer 5.5";
		}
		elseif(stristr($Agent,"MSIE 5.0")!=false)
		{
			$Browser="Internet Explorer 5";
		}
		elseif(stristr($Agent,"MSIE 4.0")!=false)
		{
			$Browser="Internet Explorer 4";
		}
		elseif(stristr($Agent,"MSIE 3.0")!=false)
		{
			$Browser="Internet Explorer 3";
		}
		elseif(stristr($Agent,"MSIE")!=false)
		{
			$Browser="Internet Explorer";
		}
		elseif(stristr($Agent,"Firefox/2.0")!=false)
		{
			$Browser="Mozilla FireFox 2.0";
		}
		elseif(stristr($Agent,"Firefox")!=false)
		{
			$Browser="Mozilla FireFox";
		}
		elseif(stristr($Agent,"Netscape/8.1")!=false)
		{
			$Browser="Netscape 8.1";
		}
		elseif(stristr($Agent,"Netscape/7.1")!=false)
		{
			$Browser="Netscape 7.1";
		}
		elseif(stristr($Agent,"Netscape6/")!=false)
		{
			$Browser="Netscape 6";
		}
		elseif(stristr($Agent,"Netscape")!=false)
		{
			$Browser="Netscape";
		}
		elseif(stristr($Agent,"Mozilla/4")!=false)
		{
			$Browser="Mozilla 4";
		}
		elseif(stristr($Agent,"Mozilla")!=false)
		{
			$Browser="Mozilla";
		}
		elseif(stristr($Agent,"Firebird")!=false)
		{
			$Browser="Firebird";
		}
		elseif(stristr($Agent,"Opera/9.1")!=false)
		{
			$Browser="Opera 9.1";
		}
		elseif(stristr($Agent,"Opera/9.0")!=false)
		{
			$Browser="Opera 9";
		}
		elseif(stristr($Agent,"Opera/8")!=false)
		{
			$Browser="Opera 8";
		}
		elseif(stristr($Agent,"Opera")!=false)
		{
			$Browser="Opera";
		}
		elseif((stristr($Agent,"googlebot")!=false) or (stristr($Agent,"slurp")!=false) or (stristr($Agent,"baiduspider")!=false) or (stristr($Agent,"iaskspider")!=false))
		{
			$Browser="搜索引擎";
		}
		if($Browser=="")
		{
			$Browser="未知浏览器";
		}
		return $Browser;
	}

	//获取目录大小
	function DirSize($DirName)
	{
		if(!stristr($_ENV["OS"],"windows") and $DirName=="."){ $DirName="./"; }
		if(file_exists($DirName) and is_dir($DirName))
		{
			$TempDirName=explode("/",dirname($DirName));
			if($TempDirName[0]!=$GLOBALS["DirName"] and $GLOBALS["DirName"]!="./")
			{
				$GLOBALS["DirName"]      = $DirName;
				$GLOBALS["DirSize"]      = 0;
				$GLOBALS["DirSpaceSize"] = 0;
			}
			$DirHead=opendir($DirName);
			while($Files=readdir($DirHead))
			{
				if($Files!="." and $Files!=".." and $Files!="")
				{
					if(is_dir($DirName."/".$Files))
					{
						DirSize($DirName."/".$Files);
					}
					else
					{
						$GLOBALS["DirSize"]+=filesize($DirName."/".$Files);
						if(filesize($DirName."/".$Files)<=4096)
						{
							$GLOBALS["DirSpaceSize"]+=4096;
						}
						else
						{
							$GLOBALS["DirSpaceSize"]+=filesize($DirName."/".$Files);
						}
					}
				}
			}
			closedir($DirHead);
			return array($GLOBALS["DirSize"],$GLOBALS["DirSpaceSize"]);
		}
		else
		{
			return false;
		}
	}

	//链接刷新
	function ReWriteLinks()
	{
		$LinkData    = TextDB_SearchData("PicLinks");
		$ReWriteData = "/*图片友情链接*/";
		if($LinkData)
		{
			foreach($LinkData as $K=>$Link)
			{
				$ReWriteData.="\n.link_".$K."{ background:url(".$Link["网站LOGO"].") #ddd; }";
			}
		}
		TextDB_FileWrite("links.css","w",$ReWriteData);
	}
?>